package com.lizhi.yun.sync.rsz.handler;/**
 * @program: hbsf_yun
 * @name RszTrajectorySelfHandler
 * @description: 自定义处方上传
 * @author: lizhi
 * @create: 2021-11-17 08:43
 */

import com.lizhi.common.yun.entity.RpcServicePOJO;
import com.lizhi.common.yun.enums.HeartBeartEnum;
import com.lizhi.utils.StringUtils;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.rsz.dao.RszTrajectorySelfDao;
import com.lizhi.yun.db.rsz.entity.RszTrajectorySelfEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *@program: hbsf_yun
 *@name RszTrajectorySelfHandler
 *@description: 自定义处方上传
 *@author: lizhi
 *@create: 2021-11-17 08:43
 */
@Slf4j
@Service
public class RszTrajectorySelfSyncHandler {

    @Resource
    private RszTrajectorySelfDao rszTrajectorySelfDao;

    public String recv(String json){
        RpcServicePOJO rpcServicePOJO = new RpcServicePOJO();
        try {
            RszTrajectorySelfEntity rszTrajectorySelfEntity = SamJsonUtil.toObject(json, RszTrajectorySelfEntity.class);
            log.info("康复磨砂卓自定义处方上传:{}", rszTrajectorySelfEntity);
            Map<String, Object> map = new HashMap<>();
            map.put("selfId", rszTrajectorySelfEntity.selfId);
            map.put("hospitalId", rszTrajectorySelfEntity.hospitalId);
            map.put("hospitalSystemId", rszTrajectorySelfEntity.hospitalSystemId);
            List<RszTrajectorySelfEntity> rszTrajectorySelfEntities = rszTrajectorySelfDao.selectByMap(map, null);
            if (rszTrajectorySelfEntities.size() > 0){
                rszTrajectorySelfDao.updateByIdSelective(rszTrajectorySelfEntity);
            } else {
                rszTrajectorySelfEntity.lid = StringUtils.newId();
                rszTrajectorySelfDao.insertRecord(rszTrajectorySelfEntity);
            }
            rpcServicePOJO.setErrorCode(HeartBeartEnum.HEART_BEART_000000.getEnValue());
            rpcServicePOJO.setMessage(HeartBeartEnum.HEART_BEART_000000.getEnName());
        } catch (Exception e){
            e.printStackTrace();
        }
        return SamJsonUtil.toJson(rpcServicePOJO);
    }
}
